What major steps we should follow, while developing the new website in asp.net [about Session concept]

Ashok Kumar 201 Reputation points
2022-11-23T11:18:22.613+00:00

I'm new to this concept and I'm developing the new website in my organization but I'm very sure I don't have that much of experience to me for maintaining the sessions and some extra required things so, to achieve this session concept I have
written like below.

I have read some concepts about sessions

ex:-

In masterpage pageload event I written this code :-

   if (Session["Admin"] != null)  
   {  
   Response.ClearHeaders();  
               Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");  
               Response.AddHeader("Pragma", "no-cache");  
   }  

And in same masterpage on logout button event I written this code

   if (Session["Admin"] != null)  
           {  
               FormsAuthentication.SignOut();  
               Session["Admin"] = null;  
               Session.Abandon();  
               Session.RemoveAll();  
               Session.Clear();  
           }  
           Response.Redirect("~/Admin/Login.aspx");  

But I'm not sure this code is correct or not
can any one suggest me
how to create a website ?
what kind of precautions we should take before creating a website ?

Please advise.

Thanks

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,404 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AgaveJoe 27,581 Reputation points
    2022-11-23T11:40:26.92+00:00

    how to create a website ?

    Unclear. Are you receiving an error creating a website with Visual Studio?

    what kind of precautions we should take before creating a website ?

    Use Forms Authentication for authorization not Session. Forms Authentication is a library that comes with ASP.NET, configured in the web.config, works with Web Forms authentication/authorization server controls, and works with standard ASP.NET authorization.

    An Overview of Forms Authentication (C#)
    Implement forms-based authentication in an ASP.NET application by using C#.NET

    Session is typically the wrong tool for authorization/authentication. Session does not scale well and Session is volatile by definition. You'll need to write and test an entire authentication/authorization process while ASP.NET comes with Forms Authentication out-of-the-box.

    Lastly, consider creating new development in the latest .NET 7 framework rather than .NET framework which ended with version 4.8.

    Tutorial: Get started with Razor Pages in ASP.NET Core


  2. Lan Huang-MSFT 28,826 Reputation points Microsoft Vendor
    2022-11-24T03:01:43.63+00:00

    Hi @Ashok Kumar ,

    But I'm not sure this code is correct or not

    Have you run it to see if it works?
    ASP.NET session state enables you to store and retrieve values for users as they browse ASP.NET pages in your Web application.
    For details on how to use it, please refer to the tutorial.
    ASP.NET Session State Overview

    how to create a website ?

    You can create ASP.NET Web Site projects directly in Visual Studio.
    263704-image.png

    what kind of precautions we should take before creating a website ?

    I think you can design clean and clear layouts; use effective typography to enhance readability; make navigation easier; reduce site load time with proper design: such as using CSS, avoiding nested tables, removing redundant whitespace, keeping code Cleaning, splitting long pages into multiple shorter pages, reducing the number of plugins, reducing scr ipts, and removing unnecessary content images.
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.