将 xsl 代码迁移到 asp.net / c#
我被要求将一些代码迁移到我们新的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的事情:
然后使用您的 applicationUrl 但您稍后需要...大概是一些重定向或其他...
Something like this:
Then use your applicationUrl however you need to later...presumably some redirect or other...
像这样的事情应该可以帮助你完成大部分工作。如果您可以提供有关如何连接 URL 的详细信息,我将更新我的答案:
取决于“app”是否发生更改,这可能是最简单的方法:
如果您需要根据用户代理对路径进行进一步操作,你可以这样做:
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:
If you need to do further manipulation to the path based on the user agent, you can do something like this: