简体   繁体   English

ASP.NET:登录会话HTML和ASPX

[英]Asp.net: login session html and aspx

I am confused how to create my login session with following layout of my page. 我对如何使用页面的以下布局创建登录会话感到困惑。

  1. I have a HTML page which consist of table data Insert, Update, Print, Delete options. 我有一个HTML页面,其中包含表格数据的“插入”,“更新”,“打印”,“删除”选项。 Now I would like to create a login session to get access to this options I don't know how to do that. 现在,我想创建一个登录会话来访问此选项,但我不知道该怎么做。 If I had a webform containing this web form I didn't had problem but this is a HTML page (requirement) to create first session then go on to next step which selecting these options. 如果我有一个包含此Web表单的Web表单,则没有问题,但这是创建第一个会话的HTML页面(要求),然后继续下一步选择这些选项。
  2. I have multiple database in my server to I also have to create dropdown list to select this specific database. 我的服务器中有多个数据库,我还必须创建下拉列表以选择此特定数据库。

Is there any solution to this. 有什么解决办法吗? Also I have my connection string from web.config which creates the session. 我也有来自web.config的连接字符串,它创建了会话。

Layout: 布局:

HTML file which have above list option to alter your database including login script which gives access (let's call this as index.html). 具有上述列表选项的HTML文件可以更改您的数据库,包括允许访问的登录脚本(我们将其称为index.html)。 Now when I login with above query all this options gets activated and I am able to go to this 4 web forms. 现在,当我使用上述查询登录时,所有这些选项均被激活,我可以转到这4个Web表单。

I have 4 web forms which is .aspx(related to Insert, Update, Print, Delete). 我有4个.aspx的Web表单(与插入,更新,打印,删除有关)。

web.config web.config

    <?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
<appSettings>

    <add key="SQLConn" value="Data Source=server name;Initial Catalog=database name;Persist Security Info=True;User ID=ID;Password=password" />


  </appSettings>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>

</configuration>

Now I don't know how to program this which creates session for both HTML and aspx pages. 现在,我不知道如何编程,这会为HTML和ASPX页面创建会话。

You can use either ASP.NET Universal Providers or ASP.Net Identity . 您可以使用ASP.NET通用提供程序ASP.Net标识

It will let you create a role based authentication. 它将允许您创建基于角色的身份验证。

Basically, you place the html inside a folder. 基本上,您将html放在文件夹中。 In the folder, you create a web.config like this. 在该文件夹中,您将像这样创建一个web.config。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <authorization>
      <allow roles="Administrators" />
      <deny users="*"/>
    </authorization>
  </system.web>
</configuration>

If you think Membership Providers are very heavy for your appliation, you can hand-roll your own authentication like this . 如果您认为会员资格提供者对于您的申请非常繁重,则可以像这样手动滚动您的身份验证。

FYI: If you have a question regarding Membership Providers, please search in SO first before creating a new question. 仅供参考:如果您有关于会员资格提供者的问题,请在创建新问题之前先在SO中搜索。

To answer the first question: 要回答第一个问题:

Save a cookie locally, lets say "login=true" check if this cookie named "login" contains a value of "true". 在本地保存一个cookie,说“ login = true”,检查此名为“ login”的cookie是否包含“ true”值。 Once checked, show the options for the table in JQUERY. 选中后,在JQUERY中显示表的选项。 For instance, hide the div that contains these options after you check if the cookie has the value "true" 例如,在检查Cookie的值是否为“ true”后,隐藏包含这些选项的div

This is not the best way to deal with login issues. 这不是处理登录问题的最佳方法。 You should build a page that checks the session at the server side and this page should be a ASPX page. 您应该构建一个页面来检查服务器端的会话,并且该页面应该是ASPX页面。

Second question: 第二个问题:

Create two connection strings. 创建两个连接字符串。 Check if dropdown value "A" was selected, and access the database using the first connection string, if "B" was selected, use the second connection string. 检查是否选择了下拉值“ A”,并使用第一个连接字符串访问数据库;如果选择了“ B”,则使用第二个连接字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM