Click here to Skip to main content
15,887,365 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I didn't know to set the virtual directory path .I know to set physical path of application.I think it must be the setting in IIS server. If Yes then please let me know how to do??

What I have tried:

I am trying to set virtual path folder in cookie path in asp.net application. PLease let me know what to make changes. As my application is on IIS server for ASP.net application
Posted

1 solution

In ASP.NET, when you set a cookie, the path can be a virtual or a physical path. If you want to set the virtual path in a cookie, you can do so in your ASP.NET code without explicitly configuring anything in IIS. Please make sure the expiration time for the cookies.
C#
// Set a cookie with a virtual path
HttpCookie myCookie = new HttpCookie("MyCookie");
myCookie.Value = "CookieValue";
myCookie.Path = "/virtualpath";
Response.Cookies.Add(myCookie);
You can also refer to the below solution:
https://stackoverflow.com/questions/54362266/configure-the-cookie-path-with-a-virtual-directory-in-addsession[^]
 
Share this answer
 
Comments
Maciej Los 12-Dec-23 16:23pm    
5ed!
Divya Shrivastav 19-Dec-23 5:08am    
But this will create new cookie :
// Set a cookie with a virtual path
HttpCookie myCookie = new HttpCookie("MyCookie");
myCookie.Value = "CookieValue";
myCookie.Path = "/virtualpath";
Response.Cookies.Add(myCookie);



In my application already the asp.net session ID is generating when I used <sessionstate> in web.config.

now I want to modified the path for the same:
ASP.net_SessionId path should be root/login.aspx
.ASPXAUTH path should be root/login.aspx

here root will be my virtual directory
and please let me know did I need to make any root folder or I need to make configurtion anywhere in IIS


I have not written manually anywhere in file its automatically gives the value
Please guide asap
Divya Shrivastav 19-Dec-23 6:32am    
@M Imran Ansari

But this will create new cookie :
// Set a cookie with a virtual path
HttpCookie myCookie = new HttpCookie("MyCookie");
myCookie.Value = "CookieValue";
myCookie.Path = "/virtualpath";
Response.Cookies.Add(myCookie);



In my application already the asp.net session ID is generating when I used <sessionstate> in web.config.

now I want to modified the path for the same:
ASP.net_SessionId path should be root/login.aspx
.ASPXAUTH path should be root/login.aspx

here root will be my virtual directory
and please let me know did I need to make any root folder or I need to make configurtion anywhere in IIS


I have not written manually anywhere in file its automatically gives the value
Please guide asap

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900