Tuesday, March 8, 2022

IdentityServer4 .NET Core Ajax Call not working after page is idle for several minutes #Solved

I have faced this problem while trying to implement IdentityServer4 in Microservice .net core project. I tried several codes and spend many days on this.

Finally, it's working fine. I have changed the Cookie settings in both the client-side and Identity server-side application configs.

Please try this and if anyone finds any better solutions, please let me know. Enjoy :)

Client-Side Config

 .AddCookie("Cookies", c =>  
   {  
     c.Cookie.SameSite = SameSiteMode.None;  
     c.Cookie.SecurePolicy = CookieSecurePolicy.Always;  
     c.Cookie.IsEssential = true;  
     c.SlidingExpiration = true;  
     c.ExpireTimeSpan = System.TimeSpan.FromHours(60);  
   }  

In the AddOpenIdConnect set

  options.UseTokenLifetime = false;  

IdentityServer Config

 builder.Services.Configure<CookieAuthenticationOptions>(IdentityServerConstants.DefaultCookieAuthenticationScheme, options =>  
 {  
   options.Cookie.SameSite = SameSiteMode.None;  
   options.Cookie.SecurePolicy = CookieSecurePolicy.Always;  
   options.Cookie.IsEssential = true;  
   options.SlidingExpiration = true;  
   options.ExpireTimeSpan = System.TimeSpan.FromHours(60);  
 });  

Usually, for Cookie-related problems, we don't need to adjust anything on the IdentityServer side.

But it is a little bit complex for me, that's why I have added the settings to both configs.

Monday, March 7, 2022

SocketException: An attempt was made to access a socket in a way forbidden by its access permissions.

I restarted this service: Host Network Service on windows Services program. And it worked. Open windows terminal as Admin and run the following commands one by one.

 Step 1  
 ----------------------  
 net stop hns  

 Step 2  
 ----------------------  
 net start hns  

Sunday, October 28, 2018

Search Inside a SQL Procedure

 SELECT DISTINCT  
     o.name AS Object_Name,  
     o.type_desc  
  FROM sys.sql_modules m  
     INNER JOIN  
     sys.objects o  
      ON m.object_id = o.object_id  
  WHERE m.definition Like '%YourText%'   

Tuesday, June 19, 2018

Access IIS Localhost From Another Computer


  1. Open cmd as an administrator.
  2. Allow the ports to be accessed by the firewall.
  3.  >netsh advfirewall firewall add rule name="Open Port 3000" dir=in action=allow protocol=TCP localport=3000  
    
    Here we are assuming that my project is on port 3000.
  4. Allow IIS to use your IP and machine hostnames. You can choose to use both or just one.
  5.   > netsh http add urlacl url=http://pc-hostname:3000/ user=everyone  
      > netsh http add urlacl url=http://10.0.1.10:3000/ user=everyone  
    
    Here we are assuming the IP address of my machine is 10.0.1.10
  6. Add the hostnames to your local IIS configuration.
    1. Navigate to "Documents\IISExpress\config"
    2. Open "applicationhost.config"
    3. Locate the applications you need to enable remote access for. In the case of my "RemoteAccess" project, you're looking for this:
    4.  <site name="RemoteAccess.web" id="17">  
        <application path="/" applicationPool="Clr4IntegratedAppPool">  
          <virtualDirectory path="/" physicalPath="C:\Users\Justin Walker\Documents\Visual Studio 2013\Projects\Remote Access\RemoteAccess.Web" />  
        </application>  
        <bindings>  
          <binding protocol="http" bindingInformation="*:3000:localhost" />  
        </bindings>  
       </site>  
      
    5. Add "binding" directives under "bindings." My changed configs look like this.
    6.  <site name="RemoteAccess.web" id="17">  
        <application path="/" applicationPool="Clr4IntegratedAppPool">  
          <virtualDirectory path="/" physicalPath="C:\Users\Justin Walker\Documents\Visual Studio 2013\Projects\Remote Access\RemoteAccess.Web" />  
        </application>  
        <bindings>  
          <binding protocol="http" bindingInformation="*:3000:localhost" />  
          <binding protocol="http" bindingInformation="*:3000:pc-hostname" />  
          <binding protocol="http" bindingInformation="*:3000:10.0.1.10" />  
        </bindings>  
       </site>