具有 Owin Security 的 Steam webforms - 在 ASPX 而不是 CSHTML 中实现功能

Steam webforms with Owin Security - implement function in ASPX instead of CSHTML

背景:我使用 ASPX 文件和网络表单(作为我的日常工作),但从未真正使用过 Razor (.cshtml)。

我正在尝试创建一个使用 Owin.Security.Providers 登录 Steam 的网站。

当我执行 Install-Package Install-Package Owin.Security.Providers 并从 https://steamcommunity.com/dev/apikey 实现 API 时,我注意到相应的按钮在 Razor 中实现,如图所示以下。

 using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) {
            @Html.AntiForgeryToken()
            <div id="socialLoginList">
                <p>
                    @foreach (AuthenticationDescription p in loginProviders) {
                        <button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
                    }
                </p>
            </div>

问题:

有没有办法在 ASPX 页面而不是 CSHTML 页面中获得与上面相同的功能?

是不是下面的代码让按钮link用于登录?

using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) {

Razor 可以简单地转换为 ASPX 语法。

如果您在 ASP.NET MVC 上下文中使用 ASPX 语法,您可以使用 Html 助手,就像在 Razor 中一样:

<% using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) { %>
    <%= Html.AntiForgeryToken %>
    <div id="socialLoginList">
        <p>
        <% foreach( AuthenticationDescription p in loginProviders ) { %>
            <button type="submit" class="btn btn-default" id="<%= p.AuthenticationType %>" name="provider" value="<%= p.AuthenticationType %>" title="Log in using your <%= p.Caption %> account"><%= p.AuthenticationType %></button>
            <% } // foreach %>
        </p>
    </div>
<% } // using %>

(注意:对于应该 HTML 编码的输出,使用 <%: 而不是 <%=。我不知道你的输出中的哪些字符串应该编码或不编码。

如果您在非 MVC 上下文中使用它,那么您需要将 Html 助手替换为文字 HTML。 不要使用 WebControls(如 <asp:Form>),因为您会失去对标记的控制: