将 xsl 代码迁移到 asp.net / c#

发布于 2024-12-03 02:46:51 字数 1505 浏览 6 评论 0原文

我被要求将一些代码迁移到我们新的 ASP.NET Web 应用程序。但我对asp.net非常不熟悉。

以下代码块检测用户设备并相应地更改 url。我需要使用 asp.net / c# 做出相同的逻辑,但我不知道从哪里开始。

非常感谢任何帮助。

    <xsl:variable name="useragent" select="lower-case(request:getHeader($request, 'user-agent'))"/>
<xsl:variable name="is_iphone" select="string(contains($useragent, 'iphone;') or contains($useragent, 'ipad;') or contains($useragent, 'ipod;'))"/>
<xsl:variable name="is_blackberry" select="string(contains($useragent, 'blackBerry'))"/>
<xsl:variable name="is_android" select="string(contains($useragent, 'android'))"/>
<xsl:variable name="application_url">
    <xsl:choose>
        <xsl:when test="$is_iphone = 'true'">
            <xsl:value-of select="f:getEnvParameter(concat('url.app.iphone.', $param_client), '')"/>
        </xsl:when>
        <xsl:when test="$is_blackberry = 'true'">
            <xsl:value-of select="f:getEnvParameter(concat('url.app.blackberry.', $param_client), '')"/>
        </xsl:when>
        <xsl:when test="$is_android = 'true'">
            <xsl:value-of select="f:getEnvParameter(concat('url.app.android.', $param_client), '')"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="''"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>
<xsl:variable name="application_url_exists" select="string-length(string($application_url)) != 0"/>

I have been asked to migrate some code to our new asp.net web app. but I am extremely unfamiliar with asp.net.

The following block of code detects the user device and changes the url accordingly. I need to make the same logic using asp.net / c# but I have no clue where to start.

Any help at all is very appreciated.

    <xsl:variable name="useragent" select="lower-case(request:getHeader($request, 'user-agent'))"/>
<xsl:variable name="is_iphone" select="string(contains($useragent, 'iphone;') or contains($useragent, 'ipad;') or contains($useragent, 'ipod;'))"/>
<xsl:variable name="is_blackberry" select="string(contains($useragent, 'blackBerry'))"/>
<xsl:variable name="is_android" select="string(contains($useragent, 'android'))"/>
<xsl:variable name="application_url">
    <xsl:choose>
        <xsl:when test="$is_iphone = 'true'">
            <xsl:value-of select="f:getEnvParameter(concat('url.app.iphone.', $param_client), '')"/>
        </xsl:when>
        <xsl:when test="$is_blackberry = 'true'">
            <xsl:value-of select="f:getEnvParameter(concat('url.app.blackberry.', $param_client), '')"/>
        </xsl:when>
        <xsl:when test="$is_android = 'true'">
            <xsl:value-of select="f:getEnvParameter(concat('url.app.android.', $param_client), '')"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="''"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>
<xsl:variable name="application_url_exists" select="string-length(string($application_url)) != 0"/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北音执念 2024-12-10 02:46:51

像这样的事情:

//create your application url - for whatever you use this for after
            var applicationUrl = string.Empty;
            //Get the user agent
            var userAgent = Request.ServerVariables["HTTP_USER_AGENT"];
            //test the useragent and set application url
            if(userAgent.Contains("blackBerry"))
            {
                applicationUrl = "url.app.blackberry";
            } else if(userAgent.Contains("android"))
            {
                applicationUrl = "url.app.android";
            }...etc

然后使用您的 applicationUrl 但您稍后需要...大概是一些重定向或其他...

Something like this:

//create your application url - for whatever you use this for after
            var applicationUrl = string.Empty;
            //Get the user agent
            var userAgent = Request.ServerVariables["HTTP_USER_AGENT"];
            //test the useragent and set application url
            if(userAgent.Contains("blackBerry"))
            {
                applicationUrl = "url.app.blackberry";
            } else if(userAgent.Contains("android"))
            {
                applicationUrl = "url.app.android";
            }...etc

Then use your applicationUrl however you need to later...presumably some redirect or other...

ら栖息 2024-12-10 02:46:51

像这样的事情应该可以帮助你完成大部分工作。如果您可以提供有关如何连接 URL 的详细信息,我将更新我的答案:

取决于“app”是否发生更改,这可能是最简单的方法:

string applicationUrl = String.Format("mysiteurl.app.{0}", Request.UserAgent.ToLower());

如果您需要根据用户代理对路径进行进一步操作,你可以这样做:

string userAgentPath = String.Empty;

switch (Request.UserAgent.ToLower())
{
    case "iphone":
        userAgentPath = "app.iphone";
        break;
    case "blackberry":
        userAgentPath = "app.blackberry";
        break;
    case "android":
        userAgentPath = "app.android";
        break;
}

string applicationUrl = String.Format("mysiteurl.{0}", userAgentPath);

Something like this should get you most of the way there. If you can provide details on how to concatenate the URL, I will update my answer:

Depending on if "app" changes at all, this might be the simplest way:

string applicationUrl = String.Format("mysiteurl.app.{0}", Request.UserAgent.ToLower());

If you need to do further manipulation to the path based on the user agent, you can do something like this:

string userAgentPath = String.Empty;

switch (Request.UserAgent.ToLower())
{
    case "iphone":
        userAgentPath = "app.iphone";
        break;
    case "blackberry":
        userAgentPath = "app.blackberry";
        break;
    case "android":
        userAgentPath = "app.android";
        break;
}

string applicationUrl = String.Format("mysiteurl.{0}", userAgentPath);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文