这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq


总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。

你知道的是什么?


当前回答

If you use web services instead WCF services, you can still use standard .Net membership to enforce authentication and login session behaviour on a set web services similarly to a how you would secure web site with membership forms authentication & without the need for a special session and/or soap headers implementations by simply calling System.Web.Security.FormsAuthentication.SetAuthCookie(userName, false) [after calling Membership.ValidateUser(userName, password) of course] to create cookie in the response as if the user has logged in via a web form. Then you can retrieve this authentication cookie with Response.Cookies[].Value and return it as a string to the user which can be used to authenticate the user in subsequent calls by re-creating the cookie in the Application_BeginRequest by extracting the cookie method call param from the Request.InputStream and re-creating the auth cookie before the membership authenticates the request this way the membership provider gets tricked and will know the request is authenticated and enforce all its rules.

将此cookie返回给用户的示例web方法签名如下: 字符串登录(用户名、密码)

后续web方法调用示例如下: 字符串DoSomething(字符串authcookie,字符串methodParam1,int methodParam2等,等),你需要提取authcookie(这是从登录方法获得的值)参数从请求。InputStreamis

这也模拟了一个登录会话并调用FormsAuthentication。签出在web方法,如注销(authcookie)将 使用户需要再次登录。

其他回答

VS阻塞的有效语法:

<input type="checkbox" name="roles" value='<%# Eval("Name") %>' 
  <%# ((bool) Eval("InRole")) ? "checked" : "" %> 
  <%# ViewData.Model.IsInRole("Admin") ? "" : "disabled" %> />

WebMethods。

你可以使用ASP。NET AJAX回调到ASPX页面中的web方法。你可以用[WebMethod()]和[ScriptMethod()]属性来修饰一个静态方法。例如:

[System.Web.Services.WebMethod()] 
[System.Web.Script.Services.ScriptMethod()] 
public static List<string> GetFruitBeginingWith(string letter)
{
    List<string> products = new List<string>() 
    { 
        "Apple", "Banana", "Blackberry", "Blueberries", "Orange", "Mango", "Melon", "Peach"
    };

    return products.Where(p => p.StartsWith(letter)).ToList();
}

现在,在你的ASPX页面你可以这样做:

<form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
        <input type="button" value="Get Fruit" onclick="GetFruit('B')" />
    </div>
</form>

并通过JavaScript调用您的服务器端方法使用:

    <script type="text/javascript">
    function GetFruit(l)
    {
        PageMethods.GetFruitBeginingWith(l, OnGetFruitComplete);
    }

    function OnGetFruitComplete(result)
    {
        alert("You got fruit: " + result);
    }
</script>

这似乎是一个巨大而模糊的问题…… 但我将在这里介绍Reflection,因为它允许我做一些非常强大的事情,如可插拔的DALs等。

可以将ASPX页面打包到一个库(.dll)中,并将它们与ASP. dll一起提供。净引擎。

您需要实现自己的VirtualPathProvider,它将通过Relfection特定的DLL加载,或者您可以在路径名中包含DLL名称。由你决定。

当覆盖VirtualFile时,奇迹发生了。方法,在其中从程序集类返回ASPX文件作为资源:Assembly. getmanifestresourcestream。ASP。NET引擎将处理资源,因为它是通过VirtualPathProvider提供的。

这允许插件页面,或者像我所做的那样,使用它来包含带有控件的HttpHandler。

默认情况下,任何web表单页面都继承自System.Web.UI.Page类。如果您希望您的页面继承自自定义基类,继承自System.Web.UI.Page怎么办?

有一种方法可以约束任何页面从您自己的基类继承。只需在web.config中添加一行:

<system.web>
    <pages pageBaseType="MyBasePageClass" />
</system.web>

注意:只有当你的类是一个独立的类时,这才有效。我的意思是一个没有隐藏代码的类,它看起来像<%@ Page Language=" c# " AutoEventWireup="true" %>