小编Dou*_*son的帖子

动态设置 OWIN 重定向 uri

我正在使用 OWIN 通过 ASP.NET MVC 应用程序中的 Microsoft Graph API 连接到 O365。一切都在 Startup.Auth.cs 中设置,包括当前来自 web.config 的 Redirect Uri 值。身份验证工作正常。

由于我在应用程序注册中使用通配符,因此重定向 uri 可以是各种值,并且用户可以从应用程序中的任意数量的页面向 O365 进行身份验证。一旦通过身份验证,我希望它们被带回他们刚刚所在的页面,但因为重定向 uri 已经设置,它们被带回该页面。

创建 OWIN 标识上下文后,如何修改代码中其他位置的重定向 uri?

下面是启动代码的片段。

   public partial class Startup
    {
        public void ConfigureAuth(IAppBuilder app)
        {
            private static string redirectUri = ConfigurationManager.AppSettings["ida:RedirectUri"];
            ....                
            app.UseOpenIdConnectAuthentication(
               new OpenIdConnectAuthenticationOptions
               {

                   ClientId = appId,
                   Authority = "https://login.microsoftonline.com/organizations/v2.0",
                   PostLogoutRedirectUri = redirectUri,
                   RedirectUri = redirectUri,
                   Notifications = new OpenIdConnectAuthenticationNotifications
                   {
                       AuthorizationCodeReceived = async (context) =>
                       {

                           Dictionary<string, string> data = new Dictionary<string, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc owin

4
推荐指数
1
解决办法
2186
查看次数

使用TSQL解析/查询XML

我已经打了一段时间,似乎我很接近,但不是那里.我在数据库中有一个列如下所示:

<document>
<items>
<item name="one">one is the first number</item>
<item name="two">two is the second number</item>
</items>
</document>
Run Code Online (Sandbox Code Playgroud)

在这个例子中,我需要查询并返回'two is the second number'.我也想在不创建临时表的情况下这样做.目前我有:

create table #test (item1 xml)
insert into #test (item1) 
values ('<document> <items> <item name="one">one is the first number</item> <item name="two">two is the second number</item> </items> </document>')

select item1.value('(/document/items/item)[2]', 'nvarchar(max)') from #test
select item1.query('/document/items/item[@name="two"]') from #test
Run Code Online (Sandbox Code Playgroud)

第一个选择返回正确的值,但我需要知道它是第二个'索引'第二个返回我想要的但它返回整个节点两个..

我错过了什么?并且,有没有一种简单的方法来使用XML而无需转换为临时表?

xml sql t-sql

3
推荐指数
1
解决办法
4302
查看次数

Shell脚本编号文件中的行

我需要找到一种更快的方法,使用awk和sed等工具以特定方式对文件中的行进行编号.我需要每行的第一个字符以这种方式编号:1,2,3,1,2,3,1,2,3等.

例如,如果输入是这样的:

line 1
line 2
line 3
line 4
line 5
line 6
line 7
Run Code Online (Sandbox Code Playgroud)

输出需要如下所示:

1line 1
2line 2
3line 3
1line 4
2line 5
3line 6
1line 7
Run Code Online (Sandbox Code Playgroud)

这是我所拥有的一大块.$ lines是数据文件中的行数除以3.因此,对于21000行的文件,我处理此循环7000次.

export i=0
while [ $i -le $lines ]
do
    export start=`expr $i \* 3 + 1`
    export end=`expr $start + 2`
    awk NR==$start,NR==$end $1 | awk '{printf("%d%s\n", NR,$0)}' >> data.out
    export i=`expr $i + 1`
done
Run Code Online (Sandbox Code Playgroud)

基本上,它一次抓取3行,对它们进行编号,并添加到输出文件中.它很慢......然后是一些!我不知道另一种,更快,更好的方式......任何想法?

shell awk sed

2
推荐指数
2
解决办法
6014
查看次数

grep - 处理引号内的文本

我有一行文字,我正在使用grep来查看这封信是否d存在.这是一个正在发生的事情的例子:

返回1,这是正确的:

echo d file='hello world' | grep -c -w d
Run Code Online (Sandbox Code Playgroud)

返回0,这是正确的:

echo file='hello world' | grep -c -w d
Run Code Online (Sandbox Code Playgroud)

返回1,这是正确的:

echo d file='hello world d' | grep -c -w d
Run Code Online (Sandbox Code Playgroud)

返回1 - 应该返回0:

echo file='hello world d' | grep -c -w d
Run Code Online (Sandbox Code Playgroud)

我需要它来忽略单引号内的数据.是grep在这里使用的正确工具还是有其他可能有用的工具?

linux grep

2
推荐指数
1
解决办法
1229
查看次数

如何在WPF中获取组框中的控件列表

在标准的WinForms开发中,我将执行以下操作:

foreach (Control in groupBox1.Controls)
{
     MessageBox.Show(c.Name);
}
Run Code Online (Sandbox Code Playgroud)

一个人在WPF中如何做到这一点?我在GroupBox中有一个Grid和网格中的一些控件(按钮等),但似乎无法弄清楚如何获得每个控件.

.net c# wpf groupbox wpf-controls

2
推荐指数
1
解决办法
1万
查看次数

确定解决方案配置(Visual Studio)

在代码中,有没有办法确定您正在运行的"解决方案配置"?例如,'Debug'与'Release?

我有一个服务,我喜欢在Debug中的IDE中测试,现在我有bool我设置了哪个运行'service'如果设置为true(然后使用OnStart方法运行我的'main'方法),如果它设置为false我只运行'main'方法.这很好但我经常忘记在测试后重置bool然后当我去安装服务时它失败了我必须返回,重置bool,重新编译等.

如果我能以编程方式确定我在Debug中的IDE中运行,那么我可以解决这个问题.

编辑: 在考虑这一点时,我想最终我真正需要的是确定我是否正在使用ide中的"播放"应用而不是配置.这将允许我在调试或其他配置中编译.

最简单的解决方案似乎检查'System.Diagnostics.Debugger.IsAttached'

c# debugging service configuration visual-studio

1
推荐指数
1
解决办法
4353
查看次数

标签 统计

c# ×3

.net ×1

asp.net-mvc ×1

awk ×1

configuration ×1

debugging ×1

grep ×1

groupbox ×1

linux ×1

owin ×1

sed ×1

service ×1

shell ×1

sql ×1

t-sql ×1

visual-studio ×1

wpf ×1

wpf-controls ×1

xml ×1